From 84fe0707d4848827ba9645e3fd18c2851f077a35 Mon Sep 17 00:00:00 2001 From: Martin Hafskjold Thoresen Date: Tue, 25 Oct 2016 20:52:47 +0200 Subject: [PATCH] Add fix and test for #3224 --- src/cargo/ops/cargo_rustc/layout.rs | 5 +++-- tests/build.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/layout.rs b/src/cargo/ops/cargo_rustc/layout.rs index f96ce5715..18ae026e1 100644 --- a/src/cargo/ops/cargo_rustc/layout.rs +++ b/src/cargo/ops/cargo_rustc/layout.rs @@ -50,7 +50,7 @@ use std::io; use std::path::{PathBuf, Path}; use core::{Package, Workspace}; -use util::{Config, FileLock, CargoResult, Filesystem}; +use util::{Config, FileLock, CargoResult, Filesystem, human}; use util::hex::short_hash; use super::Unit; @@ -78,7 +78,8 @@ impl Layout { // the target triple as a Path and then just use the file stem as the // component for the directory name. if let Some(triple) = triple { - path.push(Path::new(triple).file_stem().unwrap()); + path.push(try!(Path::new(triple).file_stem() + .ok_or(human(format!("target was empty"))))); } path.push(dest); Layout::at(ws.config(), path) diff --git a/tests/build.rs b/tests/build.rs index 739a5b9c4..5b2358425 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -2374,3 +2374,15 @@ fn no_warn_about_package_metadata() { .with_stderr("[..] foo v0.0.1 ([..])\n\ [FINISHED] debug [unoptimized + debuginfo] target(s) in [..]\n")); } + +#[test] +fn cargo_build_empty_target() { + let p = project("foo") + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/main.rs", "fn main() {}"); + p.build(); + + assert_that(p.cargo_process("build").arg("--target").arg(""), + execs().with_status(101) + .with_stderr_contains("[..] target was empty")); +} -- 2.30.2